home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Question on char to int and back
- Date: 4 Feb 1996 11:17:58 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4f24l6$mno@news1.usa.pipeline.com>
- References: <4f1988$dnk@ns.cs.hku.hk>
- NNTP-Posting-Host: 38.8.60.5
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 04, 1996 03:30:16 in article <Re: Question on char to int and back>,
- 'kwho@csd.hku.hk (Lord Hermes)' wrote:
-
-
- >: This might seem like a trivial question but I would like to know how I
- can
- >go
- >: from reading in a char, placing it in a stack of int (ie)
- >: char c;
- >: c = cin.get()
- >: push(s,c);
- >: now if the char was a '+', it would be entered into the stack as
- 43.
- >: I know that a cout.put(c) will output it as a character but if I
- want
- >
- >: to pop it from the stack and act on it as a character how do I
- >: convert it back to a character?
- > Can it be "a = (char) (c && 0x00ff)"? (a is the character you
- >want; c is the integer you pop from the stack)
-
- A more appropriate answer is that 43 is the internal representation
- of the character '+' (in ASCII, anway). You can use this value
- directly without conversion (conversion to what?). Examples:
-
- if (c == '+') dosomething();
-
- switch (c)
- {
- case '+': doit(); break;
- case '-': doopposite(); break;
- .....
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-